package server.content;

import server.game.players.Client;

/**
 * 
 * @author Miracle
 * 
 *         Scans player accounts for possible duped items.
 * 
 */
public class DupeDefender {

	private int duperScore = 0;

	private Client c;

	public DupeDefender(final Client c) {
		this.c = c;
	}

	/**
	 * Initialises bank & inventory scan.
	 */
	public void init() {
		scanBank();
		scanInventory();
	}

	/**
	 * Scans players bank for possible suspicions.
	 */
	public void scanBank() {
		for (int i = 0; i < c.bankItems.length - 1; i++) {
			if (c.bankItems[i] < 0)
				continue;
			final int itemAmnt = c.bankItemsN[i];
			switch (c.bankItems[i]) {

			/*
			 * Rune ess.
			 */
			case 1437:
				if (itemAmnt > 3000) {
					duperScore += 10;
				}
				break;

			/*
			 * Runes.
			 */
			case 554:
			case 555:
			case 556:
			case 557:
			case 558:
			case 559:
			case 560:
			case 561:
			case 562:
			case 563:
			case 564:
			case 565:
				if (itemAmnt > 7000) {
					duperScore += 10;
				}
				break;

			/*
			 * Rares.
			 */
			case 1038:
			case 1039:
			case 1040:
			case 1041:
			case 1042:
			case 1043:
			case 1044:
			case 1045:
			case 1046:
			case 1047:
			case 1048:
			case 1049:
			case 1050:
			case 1051:
			case 1052:
			case 1053:
			case 1054:
			case 1056:
			case 1057:
				if (itemAmnt > 2) {
					duperScore += 10;
				}
				break;

			/*
			 * Coins.
			 */
			case 995:
			case 996:
				if (itemAmnt > 50000000) {
					duperScore += 10;
				}
				break;
			}
		}
	}

	/**
	 * Scan player inventory for possible suspicions.
	 */
	public void scanInventory() {
		for (int i = 0; i < c.playerItems.length; i++) {
			if (c.playerItems[i] < 0)
				continue;
			final int itemAmnt = c.playerItemsN[i];
			switch (c.playerItems[i]) {

			/*
			 * Rune ess.
			 */
			case 1437:
				if (itemAmnt > 3000) {
					duperScore += 10;
				}
				break;

			/*
			 * Runes.
			 */
			case 554:
			case 555:
			case 556:
			case 557:
			case 558:
			case 559:
			case 560:
			case 561:
			case 562:
			case 563:
			case 564:
			case 565:
				if (itemAmnt > 7000) {
					duperScore += 10;
				}
				break;

			/*
			 * Rares.
			 */
			case 1038:
			case 1039:
			case 1040:
			case 1041:
			case 1042:
			case 1043:
			case 1044:
			case 1045:
			case 1046:
			case 1047:
			case 1048:
			case 1049:
			case 1050:
			case 1051:
			case 1052:
			case 1053:
			case 1054:
			case 1056:
			case 1057:
				if (itemAmnt > 3) {
					duperScore += 10;
				}
				break;

			/*
			 * Coins.
			 */
			case 995:
			case 996:
				if (itemAmnt > 50000000) {
					duperScore += 10;
				}
				break;
			}
		}
	}

	/**
	 * Initialises and checks score.
	 */
	public void loginDuperCheck() {
		init();
		if (getDuperScore() > 0) {
			c.alertDuper(c.playerName);
		}
	}

	public int getDuperScore() {
		return duperScore;
	}

}
